/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package cn.powertalk3.server.protocol;

import org.apache.mina.common.IoHandlerAdapter;
import org.apache.mina.common.IoSession;

/**
 *
 * @author mrgaolei
 */
public class DefaultProtocol extends IoHandlerAdapter {

    @Override
    public void sessionOpened(IoSession ssn) throws Exception {
        System.out.println("session open for " + ssn.getRemoteAddress());
    }

    @Override
    public void sessionClosed(IoSession ssn) throws Exception {
        System.out.println("session closed from " + ssn.getRemoteAddress());
    }

    @Override
    public void messageReceived(IoSession ssn, Object msg) throws Exception {
        String ip = ssn.getRemoteAddress().toString();
        System.out.println("===> Message From " + ip + ": " + msg);
        ssn.write("Reply: " + msg);
        if (msg.equals("exit")) {
            ssn.close();
        }
    }
}
